package main

import (
	"fmt"
	"strconv"
	"time"

	"gitee.com/dark.H/go-utils/s"
)

func main() {
	init := byte(0b11011100)
	out := byte(0)

	c := strconv.FormatInt(int64(init), 2)
	c3 := s.Str(c[0]).ANSIGreen().A(c[1:4]).A(s.Str(c[4:7]).ANSIGreen().A(s.Str(c[7])))

	fmt.Println(" ---- test small m-sequence ----")
	fmt.Printf("%2d : %s | %d \n", -1, c3, out)
	for i := 0; i < 44; i++ {
		init = s.ByteMSeq(init)
		c := strconv.FormatInt(int64(init), 2)
		for len(c) < 8 {
			c = "0" + c
		}
		c3 := s.Str(c[0]).ANSIGreen().A(c[1:4]).A(s.Str(c[4:7]).ANSIGreen().A(s.Str(c[7])))
		fmt.Printf("%2d : %s | %d \n", i, c3, out)
	}
	fmt.Println(" ---- test encyrpt and decrypted ----")

	test := s.Str(`
	Sonnet 18  
		--- by sharkspear
Shall I compare thee to a summer's day?
Thou art more lovely and more temperate:
Rough winds do shake the darling buds of May,
And summer's lease hath all too short a date:
Sometime too hot the eye of heaven shines,
And often is his gold complexion dimm'd;
And every fair from fair sometime declines,
By chance or nature's changing course untrimm'd
But thy eternal summer shall not fade
Nor lose possession of that fair thou owest;
Nor shall Death brag thou wander'st in his shade,
When in eternal lines to time thou growest:
So long as men can breathe or eyes can see,
So long lives this and this gives life to thee.`)
	fmt.Println(test.Words())
	test = test.ANSIRandomBeautiful()
	println("raw   :", test)
	println("\nlen   :", len(test))
	key := s.Bytes("key!")
	start := time.Now()
	enc := s.Bytes(test).HXor(key)
	used := time.Since(start)
	println("\nencryed :", enc)
	s.Str("used:" + used.String()).ANSIYellow().ANSIBold().Println()
	start = time.Now()
	dec := enc.HXor(key)
	used = time.Since(start)
	decs := dec.Decode()
	decs.Print("decypt: ")
	println("\nlen   :", len(decs))

	s.Str("used:" + used.String()).ANSIYellow().ANSIBold().Println()

	fmt.Println(" ---- test hex encrypt ----")
	raw := s.Str("C:\\windows\\system32\\cmd.exe").Println("raw:")
	en := raw.HXorHex(string(key))
	en.Println()
	en.HXorHex(string(key)).Println("decry:")
	s.Str("288882f38f858987a96da29d94e2db6b936ab86ccc98bccdeff768").HXorHex("key!").Println()
}
